package com.ytq.share.controller;

import com.ytq.share.dto.CustomUserDTO;
import com.ytq.share.dto.UserItemDTO;
import com.ytq.share.entity.Student;
import com.ytq.share.entity.User;
import com.ytq.share.entity.UserCoursePO;
import com.ytq.share.service.StudentService;
import com.ytq.share.service.UserItemService;
import com.ytq.share.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Random;

/**
 * @author yuantongqin
 * description:
 * 2020/12/18
 */
@RestController
public class TestController {

    @Autowired
    UserService userService;
    @Autowired
    UserItemService userItemService;
    @Autowired
    StudentService studentService;

//    @Autowired
//    UserCourseMapper userCourseMapper;

    @GetMapping("/hello")
    public String hello(){
        User userPO = new User();
        int i = new Random().nextInt(10);
        userPO.setUserId((long) i);
        userPO.setUserName("zhang"+i);

        int y = new Random().nextInt(2);
        LocalDate now = LocalDate.now();
        int year = now.plusYears(y).getYear();
        userPO.setYear_num((long) year);
        userService.saveUser(userPO);
        return "ok";
    }

    @GetMapping("/select")
    public String getUser(Long id){
        List<User> user = userService.getUser(id);
        System.out.println(user.toString());
        return "get";
    }

    @GetMapping("/name")
    public String name(String name){
        List<User> userListByName = userService.getUserListByName(name);
        System.out.println(userListByName.toString());
        return "ok";
    }

    @GetMapping("/student")
    public String student(){
        Student student = new Student();
        student.setName("Lisi");
        student.setTeacher("change");
        studentService.saveStudent(student);
        return "s";
    }

    @GetMapping("/all")
    public String allUser(){
        List<CustomUserDTO> allUser = userService.getAllUser();
        System.out.println(allUser.toString());
        return "ok";
    }

    @GetMapping("/course")
    public void course(){
        UserCoursePO coursePO =new UserCoursePO();
        coursePO.setUserId(2L);
        coursePO.setCourseName("physical");
//        userCourseMapper.insert(coursePO);
    }

    @GetMapping("/item")
    public String item(){
        List<UserItemDTO> userItemList =
                userItemService.getUserItemList();
        System.out.println(userItemList.toString());
        return "ok";
    }

}
